#ifndef USERINFO_H
#define USERINFO_H

#include "Game/GameDefine.h"
#include "Game/SocketDefine.h"

#include "_Global/Socket/ClientSocket.h"
#include "_Global/GlobalClass.h"

#include <QObject>
#include <QList>
#include <QDebug>

#include <QUuid>

//游戏服务器信息列表
class _GameServerInfo: public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString name READ name)
public:
    //游戏服务器状态
    quint32 m_unServerID;    //服务器id
    QString m_strName;
    QString m_strIP;
    quint16 m_unPort;
    QString m_strKey;

public:
    explicit _GameServerInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_unServerID = 0;
        m_strName = "";
        m_strIP = "";
        m_unPort = 0;
        m_strKey = "";
    }

public:
    QString name() const
    {
        return m_strName;
    }
};

//用户 1个关卡学习信息
class LevelInfo : public QObject
{
    Q_OBJECT
    Q_PROPERTY(qint32 classID READ classID)
    Q_PROPERTY(qint32 levelID READ levelID)
    Q_PROPERTY(quint32 wordCount READ wordCount)
    Q_PROPERTY(quint32 unStudiedCount READ unStudiedCount)
    Q_PROPERTY(quint32 correctCount READ correctCount)
    Q_PROPERTY(quint32 mistakeCount READ mistakeCount)
    Q_PROPERTY(QString wordRecords READ wordRecords)
public:
    explicit LevelInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_nLevelID = -1;
        m_nClassID = -1;
        m_unWordCount = 0;
        m_strWordRecords = "";
    }
    virtual ~LevelInfo()
    {

    }

public:
    qint32 classID() const
    {
        return m_nClassID;
    }
    qint32 levelID() const
    {
        return m_nLevelID;
    }
    quint32 wordCount() const
    {
        return m_unWordCount;
    }
    quint32 unStudiedCount() const
    {
        int i = 0;
        quint32 n = 0;
        for(; i < m_strWordRecords.length(); i++)
        {
            if(m_strWordRecords.at(i) == 'u')
                n++;
        }
        return n;

        /*
        int n;
        QString::const_iterator ii;
        for(ii = result.constBegin(); ii != result.constEnd(); ii++)
            if(*ii == 'y')n++;
        return n;
        */
    }
    quint32 correctCount() const
    {
        int i = 0;
        quint32 n = 0;
        for(; i < m_strWordRecords.length(); i++)
        {
            if(m_strWordRecords.at(i) == 'y')
                n++;
        }
        return n;

        /*
        int n;
        QString::const_iterator ii;
        for(ii = result.constBegin(); ii != result.constEnd(); ii++)
            if(*ii == 'y')n++;
        return n;
        */
    }
    quint32 mistakeCount() const
    {
        int i = 0;
        quint32 n = 0;
        for(; i < m_strWordRecords.length(); i++)
        {
            if(m_strWordRecords.at(i) == 'n')
                n++;
        }
        return n;

        /*
        int n;
        QString::const_iterator ii;
        for(ii = result.constBegin(); ii != result.constEnd(); ii++)
            if(*ii == 'n')n++;
        return n;
        */
    }

    QString wordRecords() const
    {
        return m_strWordRecords;
    }

public:
    qint32 m_nLevelID;
    qint32 m_nClassID;
    quint32 m_unWordCount;
    //int m_CorrectCount;
    //int m_MistakeCount;
    QString m_strWordRecords;

};

//1个课程信息
class ClassInfo : public QObject
{
    Q_OBJECT
    Q_PROPERTY(quint32 classID READ classID)
    Q_PROPERTY(QString className READ className)
    Q_PROPERTY(quint32 classLevelCount READ classLevelCount)
    //Q_PROPERTY(QObjectList levelList READ levelList)
    Q_PROPERTY(QVariantMap levelMap READ levelMap)

public:
    explicit ClassInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_nClassID = 0;
        m_strClassName = "";
        m_unClassLevelCount = 0;
        //m_LevelList.clear();
        //m_mapLevel.clear();
    }
    virtual ~ClassInfo()
    {
        clearLevelMap();
    }

public:
    void clearLevelMap()
    {
        /*
        QObjectList::const_iterator ii;
        for (ii = m_LevelList.constBegin(); ii != m_LevelList.constEnd(); ++ii)
        {
            delete qobject_cast<LevelInfo*>(*ii);
            //static_cast
        }
        */

        //qDeleteAll(m_LevelList);
        //m_LevelList.clear();


        QVariantMap::const_iterator ii;
        for (ii = m_mapLevel.constBegin(); ii != m_mapLevel.constEnd(); ++ii)
        {
            delete (*ii).value<LevelInfo*>();
        }

        m_mapLevel.clear();
    }

public:
    quint32 classID() const
    {
        return m_nClassID;
    }
    QString className() const
    {
        return m_strClassName;
    }
    quint32 classLevelCount() const
    {
        return m_unClassLevelCount;
    }
    QVariantMap levelMap() const
    {
        return m_mapLevel;
    }

public:
    quint32 m_nClassID;             //课程ID
    QString m_strClassName;         //课程名
    quint32 m_unClassLevelCount;              //关卡个数
    //QObjectList m_LevelList;   //用户学习关卡信息
    QVariantMap m_mapLevel;   //用户学习关卡信息

};




//1个用户的排名信息
class PerUserGameRankingInfo : public QObject
{
    Q_OBJECT
    Q_PROPERTY(quint32 userGameID READ userGameID)
    Q_PROPERTY(quint32 type READ type)
    Q_PROPERTY(QString nickName READ nickName)
    Q_PROPERTY(qint32 scoreTotal READ scoreTotal)
    Q_PROPERTY(qint32 score READ score)

public:
    quint32 userGameID() const
    {
        return m_unUserGameID;
    }
    quint32 type() const
    {
        return m_nType;
    }
    QString nickName() const
    {
        return m_strNickName;
    }
    qint32 scoreTotal() const
    {
        return m_nScoreTotal;
    }
    qint32 score() const
    {
        return m_nScore;
    }

public:
    quint32 m_unUserGameID;
    quint32 m_nType;         //1:昨天积分总数;2:7日内积分总数
    QString m_strNickName;
    qint32 m_nScoreTotal;     //积分统计
    qint32 m_nScore;          //用户拥有积分

};

//排名信息
class RankingInfo : public QObject
{
    Q_OBJECT
    //Q_PROPERTY(QObjectList listUserGameRanking READ listUserGameRanking)

public:
    explicit RankingInfo(QObject *parent = nullptr): QObject(parent)
    {
        //m_listUserGameRankingInfo.clear();
    }
    virtual ~RankingInfo()
    {
        clearRankingInfo();
    }
public:
    void clearRankingInfo()
    {
        /*
        QObjectList::const_iterator ii;
        for (ii = m_listUserGameRankingInfo.constBegin(); ii != m_listUserGameRankingInfo.constEnd(); ++ii)
        {
            delete qobject_cast<PerUserGameRankingInfo*>(*ii);
            //static_cast
        }
        */

        QMap<int, QObjectList*>::const_iterator ii;
        for (ii = m_mapUserGameRankingInfoList.constBegin(); ii != m_mapUserGameRankingInfoList.constEnd(); ++ii)
        {
            qDeleteAll(*(ii.value()));
            //delete ii.value();
        }
        qDeleteAll(m_mapUserGameRankingInfoList);
        m_mapUserGameRankingInfoList.clear();

    }

public:
    Q_INVOKABLE QObjectList listUserGameRanking(int n) const
    {
        QObjectList list;
        return *m_mapUserGameRankingInfoList.value(n, &list);
    }

public:
    //QObjectList m_listUserGameRankingInfo;   //用户学习关卡信息
    //按 类型(周/月) 的排名 列表
    QMap<int,QObjectList*> m_mapUserGameRankingInfoList;
};


class QSqlDatabase;
class WordLib;
//玩家 学习所有信息，与服务器交互
class StudyInfo : public QObject
{
    Q_OBJECT
    Q_PROPERTY(qint32 languageType READ languageType)
    Q_PROPERTY(QVariantMap classInfoMap READ classInfoMap)

public:
    explicit StudyInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_nLanguageType = -1;          //语种，英语
        //m_mapClassInfo.clear();
    }
    virtual ~StudyInfo()
    {
        //qDebug()<<"StudyInfo析构Ing";
        clearClassInfo();
        //qDebug()<<"StudyInfo析构";
    }

public:

    void clearClassInfo()
    {
        QVariantMap::const_iterator ii;
        for (ii = m_mapClassInfo.constBegin(); ii != m_mapClassInfo.constEnd(); ++ii)
        {
            delete (*ii).value<ClassInfo*>();
        }

        m_mapClassInfo.clear();
    }
    /*
    void clearClassInfo()
    {
        QVariantMap::const_iterator ii;
        for (ii = m_mapClassInfo.constBegin(); ii != m_mapClassInfo.constEnd(); ++ii)
        {
            QVariantMap tmapAClassInfo = (*ii).value<QVariantMap>();
            QVariantMap::const_iterator jj;
            for (jj = tmapAClassInfo.constBegin(); jj != tmapAClassInfo.constEnd(); ++jj)
            {
                delete (*jj).value<ClassInfo*>();
            }
        }

        m_mapClassInfo.clear();
    }*/


    //读取所有classInfo
    bool loadClassInfoLocal(QSqlDatabase* db);
    //读取所有用户的levelInfo
    bool loadStudyInfoLocal(QSqlDatabase* db,quint32 usergameid);
    bool saveResultLocal(QSqlDatabase* db, WordLib* m_pWordLib, quint32 usergameid);

public:
    qint32 languageType() const
    {
        return m_nLanguageType;
    }

    QVariantMap classInfoMap() const
    {
        return m_mapClassInfo;
    }

public:
    qint32 m_nLanguageType;          //语种，英语
    QVariantMap m_mapClassInfo;
    //QObjectList m_mapClassInfo;   //大类

};


//每个道具
class PerItemInfo: public QObject
{
    Q_OBJECT
public:
    explicit PerItemInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_unID = 0;
        m_nType = 0;
        m_nValue = 0;
        m_nStatus = 0;
    }
    virtual ~PerItemInfo()
    {
    }

public:
    quint32 m_unID;       //物品数据库的ID
    qint32 m_nType;     //物品类型
    qint32 m_nValue;    //物品值
    qint16 m_nStatus;   //物品状态(0为不可用)
    QDateTime m_dtAddDateTime;  //买入时间
    QDateTime m_dtRequireDateTime;  //过期时间
};

//道具类
class ItemsInfo: public QObject
{
    Q_OBJECT
    Q_PROPERTY(QObjectList listItemsInfo READ listItemsInfo)  //ServerInfo列表
    Q_PROPERTY(bool canReview READ canReview)  //
    Q_PROPERTY(bool flagCorrectAnswer READ flagCorrectAnswer)  //

public:
    explicit ItemsInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_bCanReview = false;
        m_bFlagCorrectAnswer = false;
    }
    virtual ~ItemsInfo()
    {
        clearItemsInfo();
    }

public:
    void refreshItems()
    {
        m_bCanReview = false;
        m_bFlagCorrectAnswer = false;

        QObjectList::const_iterator ii;
        for(ii = m_listItems.constBegin(); ii != m_listItems.constEnd(); ii++)
        {
            if(qobject_cast<PerItemInfo*>(*ii)->m_nStatus == 0)     //不可用
                continue;

            if(qobject_cast<PerItemInfo*>(*ii)->m_nType == 1)
            {
                if(qobject_cast<PerItemInfo*>(*ii)->m_nValue == 1)       //学习卡
                    m_bFlagCorrectAnswer = true;
                else if(qobject_cast<PerItemInfo*>(*ii)->m_nValue == 2)       //复习卡
                    m_bCanReview = true;
            }
        }
        //m_GameServerUserInfo.m_ItemsInfo;
    }

    void clearItemsInfo()
    {
        /*
        QObjectList::const_iterator ii;
        for (ii = m_listUserGameRankingInfo.constBegin(); ii != m_listUserGameRankingInfo.constEnd(); ++ii)
        {
            delete qobject_cast<PerUserGameRankingInfo*>(*ii);
            //static_cast
        }
        */

        qDeleteAll(m_listItems);
        m_listItems.clear();

        m_bCanReview = false;
        m_bFlagCorrectAnswer = false;
    }

public:
    QObjectList listItemsInfo() const
    {
        return m_listItems;
    }
    bool canReview() const
    {
        return m_bCanReview;
    }
    bool flagCorrectAnswer() const
    {
        return m_bFlagCorrectAnswer;
    }

public:
    QObjectList m_listItems;

    bool m_bCanReview;         //复习卡是否存在
    bool m_bFlagCorrectAnswer; //学习卡是否存在
};


class UserLevelInfo: public QObject
{
    Q_OBJECT
public slots:
};



class WordLib;
class TcpSocket;

//用户数据
class UserInfo: public QObject
{
    Q_OBJECT
    Q_FLAGS(_TestFlag)

    Q_PROPERTY(QVariantMap gameServerInfoMap READ gameServerInfoMap)  //ServerInfo列表

    Q_PROPERTY(quint32 serverID READ serverID)  //当前ServerID
    Q_PROPERTY(QString serverName READ serverName)  //当前ServerName

    Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) //用户名
    Q_PROPERTY(quint32 gradeID READ gradeID) //学业ID
    Q_PROPERTY(QString gradeName READ gradeName) //学业名

    //GameServer信息
    Q_PROPERTY(quint32 userGameID READ userGameID)
    Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
    Q_PROPERTY(qint16 sex READ sex WRITE setSex NOTIFY sexChanged)
    Q_PROPERTY(qint32 scoreYesterday READ scoreYesterday) //积分
    Q_PROPERTY(qint32 scoreWeek READ scoreWeek) //积分
    Q_PROPERTY(qint32 scoreCount READ scoreCount WRITE setScoreCount NOTIFY scoreCountChanged) //积分


    Q_PROPERTY(QObject* studyInfo READ studyInfo)   //学习信息
    Q_PROPERTY(QObject* rankingInfo READ rankingInfo)   //排名
    Q_PROPERTY(QObject* itemsInfo READ itemsInfo)    //道具

    //道具开关(用户)
    Q_PROPERTY(bool flagCorrectAnswer READ flagCorrectAnswer WRITE setFlagCorrectAnswer NOTIFY flagCorrectAnswerChanged)    //学习卡
    Q_PROPERTY(bool canReview READ canReview WRITE setCanReview NOTIFY canReviewChanged)    //复习卡

    Q_PROPERTY(_ClientGameStatus gameStatus READ gameStatus WRITE setGameStatus NOTIFY gameStatusChanged)    //用户游戏状态

public:
    //客户端的登录状态
    enum _ClientStatus  //注意：m_pGameSocket接受的状态设置全部需要修改!!!???
    {
        Client_IsLoginOut = 0,       //登出状态 [客户端]
        Client_IsRegisteringInfoServer,        //正在注册信息服务器 [客户端]
        Client_IsLoginingInfoServer,           //正在登录信息服务器 [客户端]
        Client_IsLoginedInfoServer,             //已经登录信息服务器

        Client_IsRegisteringGameServer,        //正在注册游戏服务器 [客户端]
        Client_IsLoginingGameServer,             //正在登录游戏服务器 [客户端]
        Client_IsLoginedGameServer             //已经登录游戏服务器
    };

    enum _TestFlag
    {
        Flag1 = 0,
        Flag2
    };

    //登录信息
    struct _LoginInfo
    {
        _ClientStatus m_ClientStatus;       //登录状态
        quint32 m_unID;         //客户id(数据库的id号)//void *m_id;
        QString m_strUserName;
        quint32 m_unGradeID; //学业
        //QString strNickName;
        QString m_strPassword;
        qint16 m_nClientType;

        _LoginInfo()
        {
            m_unID = 0;
            m_strUserName = "";
            m_strPassword = "";
            m_ClientStatus = Client_IsLoginOut;
            m_nClientType = 0;
        }
    }m_LoginInfo;


    //游戏时状态
    struct _GameInfo
    {
        _ClientGameStatus m_ClientGameStatus;     //状态!!!
        qint32  m_nGroupId;      //用户加入的 房间
        bool    m_bIsMaster;          //是否是房主!!!

        _GameInfo()
        {
            m_ClientGameStatus = _ClientGameStatus::Game_Nothing;
            m_nGroupId = -1;
            m_bIsMaster = false;
        }
    }m_GameInfo;


//游戏服务器 用户数据
    //道具
    struct _GameServerUserInfo
    {
        _GameServerUserInfo()
        {
            nScoreCount = 0;
            strNickName = "";
            nSex = -1;
            unUserGameID = 0;
            nScoreAdd = 0;
            nScoreYesterday = 0;
            nScoreWeek = 0;
        }

        quint32 unUserGameID;
        QString strNickName;     //服务器昵称
        qint16 nSex;
        qint32 nScoreYesterday;        //昨日金币统计
        qint32 nScoreWeek;        //一周金币统计
        qint32 nScoreCount;        //服务器金币总数
        qint32 nScoreAdd;         //存储本地积分的增减(传输到服务器后置0)
        ItemsInfo m_ItemsInfo;

    }m_GameServerUserInfo;

signals:
//给QML的

    void s_loginStatus(int code);  //登录
    void s_regStatus(int code);  //注册
    void s_choiceGameServerStatus(int code);  //选择服务器成功,next为-1是出错，1是需要注册昵称，为0 登录/注册 成功
    void s_regGameStatus(int code);  //注册游戏昵称帐户;1(已有人注册),2(含有禁词)

    void s_RefreshAllLevels();     //刷新当前Class的所有Level信息
    void s_RefreshRanking(int code);    //刷新排名
    void s_RefreshItems(int code);      //刷新物品

//给GameManager的
    void s_SendCodeDataToServer(TcpSocket* pSocket,QByteArray ba);

//属性信号:
    void scoreCountChanged(int newValue);
    void flagCorrectAnswerChanged(bool newValue);
    void canReviewChanged(bool newValue);
    void nickNameChanged(QString newValue);
    void userNameChanged(QString newValue);
    void sexChanged(int newValue);

    void gameStatusChanged(int newValue);


public:
    explicit UserInfo(QObject *parent = nullptr): QObject(parent)
    {
        m_pInfoSocket = nullptr;
        m_pGameSocket = nullptr;
        m_pWordLib = nullptr;
        m_unGameServerId = 0;

        m_bCanReview = false;
        m_bFlagCorrectAnswer = false;
    }
    virtual ~UserInfo()
    {
        clearGameServersInfo();
    }

public:
    //B.请求游戏服务器信息
    /*
    bool loadGameServersInfo()        //[OK]读取信息 所有游戏服务器信息
    {
        m_pInfoSocket->sendData(0x10) << (qint16)INFO_SERVER_REQUEST
                                    << (qint16)INFO_SERVER_SERVERINFO;
        m_pInfoSocket->send();
        return true;
    }*/
    //D.从游戏服务器读取用户信息
    //-1连接错误;
    int loadGameUserInfo();

    //E.读取课程信息[ok]
    bool loadClassInfo()
    {
        m_pGameSocket->sendData(0x10) << (qint16)GAME_SERVER_REQUEST
                                    << (qint16)GAME_SERVER_CLASSINFO;
        m_pGameSocket->send(false);
        return true;
    }
    //F.读取玩家学习信息[ok]
    bool loadStudyInfo()
    {
        m_pGameSocket->sendData(0x10) << (qint16)GAME_SERVER_REQUEST
                                    << (qint16)GAME_SERVER_STUDYINFO
                                    //<< unUserGameID()
                                       ;
        m_pGameSocket->send(false);
        return true;
    }
    // 发送ItemInfo
    bool loadItemsInfo()
    {
        m_pGameSocket->sendData(0x10) << (qint16)GAME_SERVER_REQUEST
                                    << (qint16)GAME_SERVER_ITEMS
                                    << serverID();
        m_pGameSocket->send(false);
        return true;
    }
    //获得排名
    bool loadRankingInfo()
    {
        m_pGameSocket->sendData(0x10) << (qint16)GAME_SERVER_REQUEST
                                    << (qint16)GAME_SERVER_RANKING
                                    << serverID()
                                    << m_LoginInfo.m_unGradeID
                                       ;
        m_pGameSocket->send(false);
        return true;
    }


    //!!!更新用户金币
    bool updateGameUserScoreInfo();

    //更新用户金币数,并nScoreAdd=0
    qint32 updateScoreCount()
    {
        //setScoreCount(ScoreCount() + m_GameServerUserInfo.nScoreAdd);
        m_GameServerUserInfo.nScoreAdd = 0;
        return scoreCount();
    }

    //U:保存学习信息
    bool saveResult(WordLib* m_pWordLib);
    bool saveClassLevel(int classID, int levelID, QString result);  //本地保存


    //U.清空 游戏服务器信息
    void clearGameServersInfo()
    {
        QVariantMap::const_iterator ii;
        for(ii = m_mapGameServerInfo.constBegin(); ii != m_mapGameServerInfo.constEnd(); ii++)
            delete (*ii).value<_GameServerInfo*>();


        //qDeleteAll(m_mapGameServerInfo);
        m_mapGameServerInfo.clear();
    }

    /*
    bool loadUserLevelInfo()
    {
        if(!m_pWordLib->isValid())
            return false;

        QString sql = "SELECT * FROM config";
        QSqlQuery query(*m_pWordLib->getDB());  //查询


        if(!query.exec(sql))
        {
            Debug_Leamus("Query config error");
            return false;
        }

        while(query.next())
        {
            m_GameConfig[query.value("Key").toString()] = query.value("Value");
        }
        query.finish();
        qDebug()<<"读取config结束:"<<m_GameConfig.count();
        return true;
    }*/

    void refreshItems()
    {
        m_GameServerUserInfo.m_ItemsInfo.refreshItems();
        setFlagCorrectAnswer(m_GameServerUserInfo.m_ItemsInfo.m_bFlagCorrectAnswer);
        setCanReview(m_GameServerUserInfo.m_ItemsInfo.m_bCanReview);
    }


protected:
    bool checkBadWord(QString word);    //检查词汇


private:
    //发送注册或登录信息
    bool sendUserInfoToLocalTest(); //[local]发送数据至本地(测试登录,读取UserInfo)

    //D.从数据库读取用户信息,m_TempDB
    //0:登录成功,读取GameUserInfo;1:没有注册GameUser
    int loadGameUserInfoLocal();

    bool loadGameServersInfoLocal();   //[local]读取信息 所有游戏服务器信息

    bool updateGameUserScoreInfoLocal();


//qml直接调用:
public slots:
    //登录/注册/选择服务器

    //C.选择游戏服务器
    bool sl_qml_ChoiceGameServer(int gameServerID);

    bool sl_qml_UserLogin(QVariant param); //
    bool sl_qml_UserReg(QVariant param);   //注册用户,暂时不用!
    bool sl_qml_GameUserReg(QVariant param); //用户 向注册游戏服务器 注册信息

    //qml调用;读取Items信息[ok]
    bool sl_qml_loadItemsInfo()
    {
        return loadItemsInfo();
    }

    //根据分数查询等级
    QVariantMap sl_getUserLevelInfo(int score);


//属性:
public:
    QVariantMap gameServerInfoMap() const
    {
        return m_mapGameServerInfo;
    }

    quint32 serverID() const
    {
        //if(m_GameServerIndex < 0 || m_mapGameServerInfo.count() <= m_GameServerIndex)
        //    return 0;
        //return ((_GameServerInfo*)(m_mapGameServerInfo.value(m_unGameServerId)))->m_unServerID;
        return m_unGameServerId;
    }
    QString serverName() const
    {
        //if(m_GameServerIndex < 0 || m_mapGameServerInfo.count() <= m_GameServerIndex)
        //    return "";
        //return ((_GameServerInfo*)(m_mapGameServerInfo.value(m_unGameServerId)))->name();
        _GameServerInfo* p = m_mapGameServerInfo.value(QString::number(m_unGameServerId),QVariant::fromValue(nullptr))
                .value<_GameServerInfo*>();
        if(p == nullptr)
            return "";
        else
            return p->name();
    }

    quint32 userGameID() const
    {
        return m_GameServerUserInfo.unUserGameID;
    }

    qint32 scoreYesterday() const
    {
        return m_GameServerUserInfo.nScoreYesterday;
    }
    qint32 scoreWeek() const
    {
        return m_GameServerUserInfo.nScoreWeek;
    }
    qint32 scoreCount() const
    {
        return m_GameServerUserInfo.nScoreCount;
    }
    void setScoreCount(qint32 n)
    {
        if(m_GameServerUserInfo.nScoreCount != n)
        {
            m_GameServerUserInfo.nScoreCount = n;
            emit scoreCountChanged(n);
        }
    }

    bool flagCorrectAnswer() const
    {
        return m_bFlagCorrectAnswer;
    }
    void setFlagCorrectAnswer(bool bNewValue)
    {
        if(m_bFlagCorrectAnswer != bNewValue)
        {
            m_bFlagCorrectAnswer = bNewValue;
            emit flagCorrectAnswerChanged(bNewValue);
        }
    }

    bool canReview() const
    {
        return m_bCanReview;
    }
    void setCanReview(bool bNewValue)
    {
        if(m_bCanReview != bNewValue)
        {
            m_bCanReview = bNewValue;
            emit canReviewChanged(bNewValue);
        }
    }

    QString nickName() const
    {
        return m_GameServerUserInfo.strNickName;
    }
    void setNickName(QString newValue)
    {
        if(m_GameServerUserInfo.strNickName != newValue)
        {
            m_GameServerUserInfo.strNickName = newValue;
            emit nickNameChanged(newValue);
        }
    }
    QString userName() const
    {
        return m_LoginInfo.m_strUserName;
    }
    void setUserName(QString newValue)
    {
        if(m_LoginInfo.m_strUserName != newValue)
        {
            m_LoginInfo.m_strUserName = newValue;
            emit userNameChanged(newValue);
        }
    }
    quint32 gradeID() const
    {
        return m_LoginInfo.m_unGradeID;
    }
    QString gradeName() const
    {
        switch(m_LoginInfo.m_unGradeID)
        {
        case 1:
            return _T("初中");
        case 2:
            return _T("高中");
        case 3:
            return _T("大学");
        case 4:
            return _T("校外");
        default:
            return _T("未知");
        }
    }


    qint16 sex() const
    {
        return m_GameServerUserInfo.nSex;
    }
    void setSex(qint16 newValue)
    {
        if(m_GameServerUserInfo.nSex != newValue)
        {
            m_GameServerUserInfo.nSex = newValue;
            emit sexChanged(newValue);
        }
    }

    _ClientGameStatus gameStatus() const
    {
        return m_GameInfo.m_ClientGameStatus;
    }

    void setGameStatus(_ClientGameStatus newValue)
    {
        if(m_GameInfo.m_ClientGameStatus != newValue)
        {
            m_GameInfo.m_ClientGameStatus = newValue;
            emit gameStatusChanged(newValue);
        }
    }

    QObject* studyInfo()
    {
        return &m_StudyInfo;
    }
    QObject* itemsInfo()
    {
        return &m_GameServerUserInfo.m_ItemsInfo;
    }
    QObject* rankingInfo()
    {
        return &m_RankingInfo;
    }

//框架
public:
    TcpSocket*  m_pInfoSocket;        //InfoServerSocket
    TcpSocket*  m_pGameSocket;        //GameInfoServerSocket
    WordLib*    m_pWordLib;          //本地数据库配置指针,由GameManager初始化

//游戏数据
public:
    StudyInfo   m_StudyInfo;        //学习记录

    QVariantMap m_mapGameServerInfo;   //游戏服务器信息列表(ID对应GameServerInfo指针)
    quint32     m_unGameServerId;         //用户选择的游戏信息服务器的ID

    RankingInfo m_RankingInfo;  //排名信息

    bool m_bCanReview;         //复习卡开关
    bool m_bFlagCorrectAnswer; //学习卡开关


    QSqlDatabase* m_pTempDB; //!!!本地临时数据库,包含用户信息,金币等


};


#endif // USERINFO_H
